package org.example.easybuy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.example.easybuy.dao.NewsDao;
import org.example.easybuy.entity.News;
import org.example.easybuy.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class NewsServiceImpl implements NewsService {

    @Autowired
    private NewsDao newsDao;

    @Override
    public PageInfo<News> getNewsPageInfo(Map<String, Object> params) {
        int pageNum=Integer.parseInt((String)params.get("pageNum"));
        int pageSize=Integer.parseInt((String)params.get("pageSize"));
        PageHelper.startPage(pageNum,pageSize,"createTime desc");
        return new PageInfo<>(newsDao.selectByTitleAndDate(params),3);
    }

    @Override
    public boolean deleteNewsById(int id) {
        return newsDao.deleteNewsById(id)==1;
    }

    @Override
    public boolean updateNews(News news) {
        return newsDao.updateNews(news)==1;
    }

    @Override
    public News selectNewsById(int id) {
        return newsDao.selectNewsById(id);
    }

    @Override
    public boolean addNews(News news) {
        return newsDao.addNews(news)==1;
    }

    @Override
    public News selectByTitle(String title) {
        return newsDao.selectByTitle(title);
    }
}
